home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / LHiResPrintout / LHiResPrintout.cp < prev    next >
Encoding:
Text File  |  1997-06-30  |  4.6 KB  |  170 lines  |  [TEXT/CWIE]

  1. /********************************************************************************\
  2.  LHiResPrintout - A subclass of LPrintout that prints at the printer's resolution
  3.  Dan Crevier - 6/19/97 <mailto:Dan.Crevier@pobox.com>
  4.  
  5.  Use an LHiResPrinter instaed of LPrintout, and then call SetMaxResolution to
  6.  print at the printer's maximum resolution.
  7.  
  8.  You can use GetResolution to get the printer's resolution in DPI
  9.  
  10.  You will probably need to move and resize the contained views to reflect the
  11.  resolution change. One way to do this is with my LProportionalSizer class,
  12.  released separately to the PP archives
  13.  
  14.  Note: text will not be automatically be resized. I've included an LHiResCaption
  15.  class for captions that will resize the text when enclosed in a LHiResPrintout
  16.  
  17.  This code is based on something Greg Payne did for TCL
  18.  Thanks to John C. Daub for lots of useful suggestions
  19.  
  20. \********************************************************************************/
  21.  
  22. #include "LHiResPrintout.h"
  23. #include <UPrintingMgr.h>
  24. #include <LCommander.h>
  25. #include <UReanimator.h>
  26.  
  27. // ---------------------------------------------------------------------------
  28. //        • CreatePrintout [static]
  29. // ---------------------------------------------------------------------------
  30. //    Return a new Printout object (and its SubPanes) from the data in
  31. //    a 'PPob' resource
  32.  
  33. LHiResPrintout*
  34. LHiResPrintout::CreatePrintout(
  35.     ResIDT        inPrintoutID)
  36. {
  37.     LCommander::SetDefaultCommander(nil);
  38.     LHiResPrintout    *thePrintout =
  39.             (LHiResPrintout*) UReanimator::ReadObjects('PPob', inPrintoutID);
  40.     thePrintout->FinishCreate();
  41.     thePrintout->mDPI = 72;
  42.  
  43.     return thePrintout;
  44. }
  45.  
  46. // ---------------------------------------------------------------------------
  47. //        • LHiResPrintout
  48. // ---------------------------------------------------------------------------
  49. //    Default Constructor
  50.  
  51. LHiResPrintout::LHiResPrintout()
  52. : LPrintout()
  53. {
  54.     mDPI = 72;
  55. }
  56.  
  57.  
  58. // ---------------------------------------------------------------------------
  59. //        • LHiResPrintout(THPrint)
  60. // ---------------------------------------------------------------------------
  61. //    Construct a Printout from an existing PrintRecord
  62.  
  63. LHiResPrintout::LHiResPrintout(
  64.     THPrint    inPrintRecordH)
  65. : LPrintout(inPrintRecordH), mDPI(72)
  66. {
  67. }
  68.  
  69.  
  70. // ---------------------------------------------------------------------------
  71. //        • LHiResPrintout
  72. // ---------------------------------------------------------------------------
  73. //    Construct a Printout from the data in a Stream
  74.  
  75. LHiResPrintout::LHiResPrintout(
  76.     LStream    *inStream)
  77. : LPrintout(inStream), mDPI(72)
  78. {
  79. }
  80.  
  81. // ---------------------------------------------------------------------------
  82. //        • SetMaxResolution
  83. // ---------------------------------------------------------------------------
  84. //    Set the printer to its maximum square resolution
  85.  
  86. void LHiResPrintout::SetMaxResolution(void)
  87. {
  88.     TGetRotnBlk    getRotnRec;
  89.     short        err = 0;
  90.     Boolean        hasPrGeneral;
  91.     
  92.     if(UPrintingMgr::OpenPrinter())
  93.     {
  94.         getRotnRec.iOpCode = getRotnOp;
  95.         getRotnRec.hPrint = mPrintRecordH;
  96.     
  97.         ::PrGeneral((Ptr) &getRotnRec);
  98.     
  99.         err = ::PrError();
  100.     
  101.         if(err == noErr )
  102.         {
  103.             hasPrGeneral = true;
  104.         }
  105.         else
  106.         {
  107.             hasPrGeneral = false;
  108.         }
  109.     }
  110.     UPrintingMgr::ClosePrinter();
  111.     
  112.     // we have PrGeneral, so we'll try to change the resolution
  113.     if (hasPrGeneral)
  114.     {
  115.         Int16    maxDPI = 0, resIndex, drvrVers;
  116.         TGetRslBlk    getResRec;
  117.         TSetRslBlk    setResRec;
  118.         
  119.         if (UPrintingMgr::OpenPrinter())
  120.         {
  121.             drvrVers = ::PrDrvrVers();
  122.         
  123.             getResRec.iOpCode = getRslDataOp;
  124.             ::PrGeneral((Ptr)&getResRec);
  125.         
  126.             if( getResRec.iError == noErr && ::PrError() == noErr )
  127.             {
  128.                 for(resIndex = 0; resIndex < getResRec.iRslRecCnt; resIndex++ )
  129.                 {
  130.                     if( getResRec.rgRslRec[ resIndex ].iXRsl ==
  131.                         getResRec.rgRslRec[ resIndex ].iYRsl &&
  132.                         getResRec.rgRslRec[ resIndex ].iXRsl > maxDPI )
  133.                     {
  134.                         maxDPI = getResRec.rgRslRec[ resIndex ].iYRsl;
  135.                     }
  136.                 }
  137.                 
  138.                 if( maxDPI != 0 && mPrintRecordH != nil )
  139.                 {
  140.                     setResRec.iOpCode = setRslOp;
  141.                     setResRec.hPrint = mPrintRecordH;
  142.                 
  143.                     setResRec.iXRsl = maxDPI;
  144.                     setResRec.iYRsl = maxDPI;
  145.                     ::PrGeneral((Ptr)&setResRec);
  146.                 }
  147.                 
  148.                 UPrintingMgr::ClosePrinter();
  149.                 
  150.                 if( setResRec.iError == noErr && ::PrError() == noErr
  151.                     && maxDPI != 0 )
  152.                 {
  153.                     mDPI = maxDPI;
  154.                     
  155.                     // resize frame
  156.                     Rect    paperRect = (**mPrintRecordH).rPaper;
  157.                     
  158.                     // Printout Frame and Image match the Paper Rectangle
  159.                     
  160.                     ResizeFrameTo(paperRect.right - paperRect.left,
  161.                                     paperRect.bottom - paperRect.top, false);
  162.                     ResizeImageTo(paperRect.right - paperRect.left,
  163.                                     paperRect.bottom - paperRect.top, false);
  164.                     PlaceInSuperImageAt(paperRect.left, paperRect.top, false);
  165.                 }
  166.             }
  167.         }
  168.     }
  169. }
  170.